<?php if(count($hmenu)){ ?>
<div id="hmenu-container">
    <div class="nav">
        <ul class="hmenu">
    <?php
    foreach($hmenu as $key =>$list)
    {
        if($list['segment'] == 'index'){ $url = '/';}
        else if($list['segment'] == '#'){ $url = base_url().uri_string().'?#';}
        else { $url = 'page/'.$list['segment'];}
        $parentClass = '';
        if(count($submenu))
        {
            $parentId = $list['page_id'];
            $filter = function($submenu) use($parentId) { return $submenu['parent_id'] == $parentId; };
            $filtered = array_filter($submenu, $filter);
            if(count($filtered))
            {
                $parentClass = 'parent-li';
            }
        }
        
        echo '<li class="'.$parentClass.'">';
        echo anchor($url, $list['title']);
        if(count($filtered))
        {
            echo '<ul class="submenu">';
            foreach($submenu as $subkey =>$item)
            {
            echo '<li>' . anchor('page/'.$item['segment'], $item['title']) . '</li>';   
            }
            echo '</ul>';   
        }
        echo '</li>';    
    }
    ?>
        </ul>
    </div>
</div>
<?php } ?>